<template>
	<div v-loading="loading"  element-loading-spinner="el-icon-loading" element-loading-background="rgba(0, 0, 0, 0.8)">	
		{{ msg }}
	</div>
</template>

<script>	
import api from '../api'
import { mapActions } from 'vuex'
import { mapMutations } from 'vuex'
import store from '../store'
	export default{
		data(){
			return{
				msg:'登录中',
				loading:false
			}
		},
		created(){
			
			var that=this;
  			this.obj=this.getUrlVars(window.location.href)
			this.INIT_STATE();
			//注入登录信息
//			that.login({
//				uid:2
//			})
			//获取登录信息，判断是否已经登录
			store.commit('INIT_STATE')
			console.log(!store.state.userlogin)
			//如果没有存 则说明是第一次进来需要重新获取
			if (!store.state.userlogin) {
     			api.getUserInfo(this.obj).then(response=>{				
				var data=eval('('+response.data+')')
				console.log(data)
				if(data.ret==0){  //线上
					//如果订购了此业务才让进去否则跳到没有订购的页面
					if(data.data.orderInfo.length>0&&data.data.role==1){
						if(data.data.orderInfo[0].serviceid=='ALN0000063'){
						that.login({
							uid:data.data.cpuid
						})						
					}else{
						that.$router.push({path:'/notOrder'})
					}
					}else{
						that.$router.push({path:'/notOrder'})
					}
//					that.$router.push({path:'/tiku/1'})
				}else{
					
					that.loading=false
				}				
			})
    		} else {
    			this.$router.push({path:'/tiku/1'})
     			this.msg=store.state.userlogin.name
    		}
			
		},
		methods:{
			...mapMutations(["INIT_STATE","USER_LOGIN"]),
			...mapActions(["login"]),
			getUrlVars(url) {
					var hash;
					var myJson = {};
					var hashes = url.slice(url.indexOf('?') + 1).split('&');
					var arr = [];
					for(var i = 0; i < hashes.length; i++) {
						hash = hashes[i].split('=');
						if(myJson.hasOwnProperty(hash[0])) {
							myJson[hash[0]] = myJson[hash[0]] + ',' + hash[1]
						} else {
							myJson[hash[0]] = hash[1]
						}
					}
					return myJson;
				}
		}
	}
</script>

<style scoped>
div{
	text-align: center;
	width: 100%;
	height: 100%;
	min-height: 400px;
}
</style>